﻿

using CRMFramework;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace CRMBiz
{
    public static class VerificationChecklistHandler
    {
        public static bool EditVerificationChecklist(int ApplicationContactID, int app_id, int Income_Payslip, int Bank_LatestMonth, int Bank_FullName, int Bank_ACBSB, int Assert_Vehicles, int Assert_CouncilRate, int Assert_Mortage, int Assert_Valuation, int IDs_Residential_Rental, int Residential_Rate, int IDs_Residential_Boarding, int IDs_UtilityBill, int IDs_PhotoID, int IDs_Card, int ExtraItemNo1, int ExtraItemNo2, int ExtraItemNo3, int ExtraItemNo4, int ExtraItemNo5, int ExtraItemNo6, int ExtraItemNo7, int ExtraItemNo8, int ExtraItemNo9, int ExtraItemNo10,string Operator)
        {
            bool flag = false;
            try
            {
                var para = new[] {
                    
                    DBhelper.SetParameter("p_ApplicationContactID", ApplicationContactID),
                    DBhelper.SetParameter("p_app_id", app_id),
                    DBhelper.SetParameter("p_Income_Payslip", Income_Payslip),
                    DBhelper.SetParameter("p_Bank_LatestMonth", Bank_LatestMonth),
                    DBhelper.SetParameter("p_Bank_FullName", Bank_FullName),
                    DBhelper.SetParameter("p_Bank_ACBSB", Bank_ACBSB),
                    DBhelper.SetParameter("p_Assert_Vehicles", Assert_Vehicles),
                    DBhelper.SetParameter("p_Assert_CouncilRate", Assert_CouncilRate),
                    DBhelper.SetParameter("p_Assert_Mortage", Assert_Mortage),
                    DBhelper.SetParameter("p_Assert_Valuation", Assert_Valuation),
                    DBhelper.SetParameter("p_IDs_Residential_Rental", IDs_Residential_Rental),
                    DBhelper.SetParameter("p_Residential_Rate", Residential_Rate),
                    DBhelper.SetParameter("p_IDs_Residential_Boarding", IDs_Residential_Boarding),
                    DBhelper.SetParameter("p_IDs_UtilityBill", IDs_UtilityBill),
                    DBhelper.SetParameter("p_IDs_PhotoID", IDs_PhotoID),
                    DBhelper.SetParameter("p_IDs_Card", IDs_Card),
                    DBhelper.SetParameter("p_ExtraItemNo1", ExtraItemNo1),
                    DBhelper.SetParameter("p_ExtraItemNo2", ExtraItemNo2),
                    DBhelper.SetParameter("p_ExtraItemNo3", ExtraItemNo3),
                    DBhelper.SetParameter("p_ExtraItemNo4", ExtraItemNo4),
                    DBhelper.SetParameter("p_ExtraItemNo5", ExtraItemNo5),
                    DBhelper.SetParameter("p_ExtraItemNo6", ExtraItemNo6),
                    DBhelper.SetParameter("p_ExtraItemNo7", ExtraItemNo7),
                    DBhelper.SetParameter("p_ExtraItemNo8", ExtraItemNo8),
                    DBhelper.SetParameter("p_ExtraItemNo9", ExtraItemNo9),
                    DBhelper.SetParameter("p_ExtraItemNo10", ExtraItemNo10),
                    DBhelper.SetParameter("hOperator",Operator),
                };

                DBhelper.ExecuteNonQuerySP("sp_updateVerificationChecklist", para);
                flag = true;
            }
            catch (Exception)
            {
                throw;
            }
            return flag;
        }

        public static DataTable GetVerificationChecklistDetail(int app_id)
        {
            DataTable dt;
            try
            {
                string sbSql = "SELECT distinct  crm_appcontactchecklist.* FROM crm_applicationcontact INNER JOIN crm_appcontactchecklist ON crm_applicationcontact.app_id = crm_appcontactchecklist.app_id where crm_appcontactchecklist.app_id='" + app_id + "' order by crm_appcontactchecklist.ApplicationContactChecklistID LIMIT 3";
                dt = DBhelper.ExecuteDataset(sbSql).Tables[0];
            }
            catch (Exception)
            {
                throw;
            }
            return dt;
        }

        public static DataTable GetExtraChecklistItem(int ExtraChecklistItemID1, int ExtraChecklistItemID2, int ExtraChecklistItemID3, int ExtraChecklistItemID4, int ExtraChecklistItemID5, int ExtraChecklistItemID6, int ExtraChecklistItemID7, int ExtraChecklistItemID8, int ExtraChecklistItemID9, int ExtraChecklistItemID10)
        {
            DataTable dt;
            try
            {
                var para = new[] {
                    DBhelper.SetParameter("@ExtraChecklistItemID1", ExtraChecklistItemID1),
                    DBhelper.SetParameter("@ExtraChecklistItemID2", ExtraChecklistItemID2),
                    DBhelper.SetParameter("@ExtraChecklistItemID3", ExtraChecklistItemID3),
                    DBhelper.SetParameter("@ExtraChecklistItemID4", ExtraChecklistItemID4),
                    DBhelper.SetParameter("@ExtraChecklistItemID5", ExtraChecklistItemID5),
                    DBhelper.SetParameter("@ExtraChecklistItemID6", ExtraChecklistItemID6),
                    DBhelper.SetParameter("@ExtraChecklistItemID7", ExtraChecklistItemID7),
                    DBhelper.SetParameter("@ExtraChecklistItemID8", ExtraChecklistItemID8),
                    DBhelper.SetParameter("@ExtraChecklistItemID9", ExtraChecklistItemID9),
                    DBhelper.SetParameter("@ExtraChecklistItemID10", ExtraChecklistItemID10),
                };

                string sbSql = "select * from crm_extrachecklistitem where (ExtraChecklistItemID!=0) and (ExtraChecklistItemID=@ExtraChecklistItemID1 or ExtraChecklistItemID=@ExtraChecklistItemID2 or ExtraChecklistItemID=@ExtraChecklistItemID3 or ExtraChecklistItemID=@ExtraChecklistItemID4 or ExtraChecklistItemID=@ExtraChecklistItemID5 or ExtraChecklistItemID=@ExtraChecklistItemID6 or ExtraChecklistItemID=@ExtraChecklistItemID7 or ExtraChecklistItemID=@ExtraChecklistItemID8 or ExtraChecklistItemID=@ExtraChecklistItemID9 or ExtraChecklistItemID=@ExtraChecklistItemID10) order by ExtraChecklistItemID";
                dt = DBhelper.ExecuteDataset(sbSql, para).Tables[0];
            }
            catch (Exception)
            {
                throw;
            }
            return dt;
        }

        //Check ApplicationContactID Exist in ApplicationContact table.
        public static DataSet IsExistApplicationContactID(int app_id)
        {
            DataSet ds;
            try
            {
                string sbSql = "Select ApplicationcontactID From crm_ApplicationContact Where app_id = " + app_id;
                ds = DBhelper.ExecuteDataset(sbSql);
            }
            catch (Exception)
            {
                throw;
            }
            return ds;
        }
    }
}
